import sys

import Config
from lib.entity import MatchResult
import re

from lib.tools import tools


def main():
    if '拉拉' in '哦拉拉啦':
        print('1')
    if '拉拉' in '拉':
        print('2')
    if '拉拉' in '拉拉哦':
        print('3')
    pass


def initPosttagdict():
    file = open(tools.getAbsPathFromRoot(Config.POSTTAG_DICT_PATH), 'r', encoding='utf-8')
    line = file.readline()
    while line:
        n, p = line.strip().split(' ')
        POSTTAG_DICT.append([n, p])
        line = file.readline()
    file.close()
    pass


# 临时词典 [[词, 词性]]
POSTTAG_DICT = []
initPosttagdict()
TEMP_DICT = []
TEMP_DICT.extend(POSTTAG_DICT)


# 句子预处理
def preProcessLine(line: str):
    # TODO 预处理表
    """
        ’（包括xxx、xxx、xxx等xxx）‘
    """
    p = re.compile(r"（.*?）")
    pp = re.compile(r'（?(?:包括)?(.*?)[、和等(?:以及)）]')

    def __change1(matched):
        inputstr = matched.group()
        resstr = ''
        if pp.search(inputstr):
            ppobjs = pp.findall(inputstr)
            resstr += '（'
            for piobj in ppobjs:
                TEMP_DICT.append([piobj, 'n'])
                resstr += piobj + '、'
            resstr = resstr[:-1] + '）'
        return resstr

    line = p.sub(repl=__change1, string=line)

    """
        next
    """

    return line


#   比较两个四元组
#   return  1 部分相等
#           2 完全相等
#           0 完全不相等
def isMatchWithMark(mr: MatchResult, markmr: MatchResult):
    matchcount = 0
    for a in mr.pi:
        for b in markmr.pi:
            if re.sub(r"您(.*?)的", "", a) == re.sub(r"您(.*?)的", "", b):  # todo p1
                matchcount += 1
                continue
    if matchcount == len(markmr.pi) and len(mr.pi) == len(markmr.pi):
        matchflag = 2
    elif matchcount == 0:
        matchflag = 0
    else:
        matchflag = 1

    return matchflag


def equalPi(api: str, bpi: str):
    if re.sub(r"您(.*?)的", "", api) == re.sub(r"您(.*?)的", "", bpi):
        return True
    return False


if __name__ == '__main__':
    main()
